package com.turnengine.client.global.error.bean;

import com.javabi.common.io.data.IDataReader;
import com.javabi.common.io.data.IDataWriter;
import java.io.IOException;

/**
 * The Command Stack Trace Serializer.
 */
public class CommandStackTraceSerializer implements ICommandStackTraceSerializer {

	@Override
	public ICommandStackTrace readObject(IDataReader reader) throws IOException {

		// Read fields
		long id = reader.readLong();
		long timestamp = reader.readLong();
		String command = reader.readString(true);
		String trace = reader.readString(true);

		// Create object
		ICommandStackTrace object = new CommandStackTrace();
		object.setId(id);
		object.setTimestamp(timestamp);
		object.setCommand(command);
		object.setTrace(trace);
		return object;
	}

	public void writeObject(IDataWriter writer, ICommandStackTrace object) throws IOException {

		// Get fields
		long id = object.getId();
		long timestamp = object.getTimestamp();
		String command = object.getCommand();
		String trace = object.getTrace();

		// Write fields
		writer.writeLong(id);
		writer.writeLong(timestamp);
		writer.writeString(command, true);
		writer.writeString(trace, true);
	}
}
